home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 051-075 / disk_056 / mcad / tdp / source / hlcross.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  3KB  |  101 lines

  1. /* hlcross.c */
  2. #include "tdp.h"
  3. void hlcross(h1_p, v1_p, h2_p, v2_p, npts, inc, dir, pass2)
  4. int *h1_p, *v1_p, *h2_p, *v2_p;
  5. short npts, inc, dir, pass2;
  6. {
  7.    register short ih,i,   /* CURRENT HORIZ PIXEL, COUNTER           */
  8.    h1, v1, h2, v2;        /* PREV, CURRENT DATA POINTS              */
  9.    short vtry, idh, idv;  /* INTERPOLATED V VALUE, DELTA-H, DELTA-V */
  10.    FFP dh, dv;            /* FFP VERSIONS OF IDH, IDV               */
  11.  
  12.    /*** PLOT LINE SEGMENTS CONNECTING LINES PLOTTED BY HLPLOT() ***/
  13.    for (i=0; i < npts; i++, h1_p+=inc, v1_p+=inc, h2_p+=inc, v2_p+=inc) {
  14.  
  15.       h1 = *h1_p; h2 = *h2_p; v1 = *v1_p; v2 = *v2_p;
  16.       idh = h2-h1; idv = v2-v1;
  17.  
  18.       /*** INIT PEN FOR NEW LINE SEGMENT ***/
  19.       pen(RESET,h1,RESET,dir);
  20.       if (!pass2) {
  21.          if (v1 >= vhicum[h1]) {
  22.             if (!vhicum[h1]) vlocum[h1] = v1-1;
  23.             vhicum[h1] = v1; pen(DOWN,h1,DATA,dir,vhicum);
  24.          }
  25.          else
  26.             pen(UP,h1,DATA,dir,vhicum);
  27.       }
  28.       else {
  29.          if (v1 <= vlocum[h1])
  30.             {vlocum[h1] = v1; pen(DOWN,h1,DATA,dir,vlocum);}
  31.          else
  32.             pen(UP,h1,DATA,dir,vlocum);
  33.       }
  34.       
  35.       /*** THE USUAL CASE: V(H) IS INTERPOLABLE IN [h1..h2] ***/
  36.       if (abs(idh) > 2) {
  37.          dv = (FFP)(idv); dh=(FFP)(idh); ih=h1+dir;
  38.          while (ih != h2) {
  39.             vtry = v1 + (short)(dv * (FFP)(ih-h1)/dh);
  40.             if (!pass2) {
  41.                if (vtry >= vhicum[ih]) {
  42.                   if (!vhicum[ih]) vlocum[ih] = vtry-1;
  43.                   vhicum[ih] = vtry; pen(DOWN,ih,INTERP,dir,vhicum);
  44.                }
  45.                else
  46.                   pen(UP,ih,INTERP,dir,vhicum);
  47.             }
  48.             else {
  49.                if (vtry <= vlocum[ih])
  50.                   {vlocum[ih] = vtry; pen(DOWN,ih,INTERP,dir,vlocum);}
  51.                else
  52.                   pen(UP,ih,INTERP,dir,vlocum);
  53.             }
  54.             ih += dir;
  55.          }
  56.       }
  57.       else {
  58.          /*** SPECIAL CASE: (NEARLY) VERTICAL LINE SEGMENT ***/
  59.          if (abs(idh) == 2) {
  60.             if (!pass2) {
  61.                if ((vtry=v1+idv/2) >= vhicum[(ih=h1+dir)]) {
  62.                   if (!vhicum[ih]) vlocum[ih] = vtry-1;
  63.                   pen(DOWN,h1,DATA,0,vhicum);
  64.                   vhicum[ih] = vtry; pen(DOWN,ih,DATA,0,vhicum);
  65.                }
  66.             }
  67.             else {
  68.                if ((vtry=v1+idv/2) <= vlocum[(ih=h1+dir)]) {
  69.                   pen(DOWN,h1,DATA,0,vlocum);
  70.                   vlocum[ih] = vtry; pen(DOWN,ih,DATA,0,vlocum);
  71.                }
  72.             }
  73.          }
  74.          else {
  75.             if (!pass2)
  76.                {if (v2 >= vhicum[h2]) pen(DOWN,h1,DATA,0,vhicum);}
  77.             else
  78.                {if (v2 <= vlocum[h2]) pen(DOWN,h1,DATA,0,vlocum);}
  79.  
  80.          }
  81.       }
  82.  
  83.       /*** FINISH THIS LINE SEGMENT ***/
  84.       if (!pass2) {
  85.          if (v2 >= vhicum[h2]) {
  86.             if (!vhicum[h2]) vlocum[h2] = v2-1;
  87.             vhicum[h2] = v2; pen(DOWN,h2,DATA,dir,vhicum);
  88.          }
  89.          else
  90.             pen(UP,h2,DATA,dir,vhicum);
  91.       }
  92.       else {
  93.          if (v2 <= vlocum[h2])
  94.             {vlocum[h2] = v2; pen(DOWN,h2,DATA,dir,vlocum);}
  95.          else
  96.             pen(UP,h2,DATA,dir,vlocum);
  97.       }
  98.    }
  99. }
  100.  
  101.